import { defineStore } from 'pinia'
import { ref } from 'vue'

// 用户模块
export const useUserStore = defineStore(
  'big-user',
  () => {
    const token = ref('') // 定义 token
    const userId = ref('') // 定义用户 ID

    const setToken = (t) => (token.value = t) // 设置 token
    const setUserId = (id) => (userId.value = id) // 设置用户 ID

    const removeToken = () => {
      token.value = ''
      userId.value = '' // 清除用户 ID
    }

    return { token, userId, setToken, setUserId, removeToken }
  },
  {
    persist: true,
  },
);